from django.conf.urls import url
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework.routers import DefaultRouter

from apps.meiduo_admin.views import home,user,image,sku,permission,group,spu,spec,option
# authorizations/
from apps.meiduo_admin.views import order,brands,channel,admins

urlpatterns = [
    # url(r'^authorizations/$', views.AdminLoginView.as_view()),

    # 按照文档修改的登陆
    # obtain_jwt_token 会进行用户名和密码的验证
    # 用户名和密码没有问题的话,会自动生成token
    url(r"^authorizations/$", obtain_jwt_token),
    # -------------- 用户统计 -------------- #
    # 统计用户量
    url(r"^statistical/total_count/$", home.TotaUserCountAPIView.as_view()),
    # 日增用户统计
    url(r"^statistical/day_increment/$", home.DailyUserAddCountAPIView.as_view()),
    # 日活用户统计
    url(r"^statistical/day_active/$", home.UserDailyActiveCountView.as_view()),
    # 日增下单用户
    url(r"^statistical/day_orders/$", home.UserDailyOrderCountAPIView.as_view()),
    # 月增用户
    url(r"^statistical/month_increment/$", home.MonthUserCountAPIView.as_view()),
    # 日分类商品访问
    url(r"^statistical/goods_day_views/$", home.CategoryAPIView.as_view()),

    # -------------- 用户相关 -------------- #

    # 查询用户
    url(r"^users/$", user.UserListAPIView.as_view()),

    # -------------- 图片管理 -------------- #
    url(r"^skus/simple/$", image.SimpleSKUAPIView.as_view()),

# -------------- sku的路由 -------------- #
    url(r"^skus/categories/$", sku.ThreeCategoryListAPIView.as_view()),
    # SPU
    url(r'^goods/simple/$',sku.SimpleSPUListAPIView.as_view()),
    # 规格信息路由
    url(r'^goods/(?P<pk>\d+)/specs/$',sku.SPUSpecsAPIView.as_view()),

    # -------------- 权限管理 -------------- #
    # 增加权限路由
    url(r'^permission/content_types/$',permission.CoententTypeAPIView.as_view()),
    # 增加分组路由方式一:
    # url(r'^permission/simple/$', group.GroupListAPIView.as_view()),
    url(r'^permission/simple/$', group.GroupView.as_view({"get":"simple"})),

    # -------------- SPU管理 -------------- #
    # 获取品牌路由
    url(r'^goods/brands/simple/$', spu.SPUGoodsView.as_view({"get":"brands"})),
    # 一级分类路由
    url(r'^goods/channel/categories/$', spu.SPUGoodsView.as_view({"get":"channel"})),
    # 二级,三级分类路由
    url(r'^goods/channel/categories/(?P<pk>\d+)/$', spu.SPUGoodsView.as_view({"get":"channel2"})),

    # -------------- 规格选项表管理 -------------- #
    url(r'^goods/specs/simple/$', option.SpecificationOptionView.as_view({"get":"specs"})),

    # -------------- 新增管理员 -------------- #
    url(r'^permission/groups/simple/$', admins.SimpleGroupView.as_view()),

]

#　视图集的路由
# 1. 创建router实例
router = DefaultRouter()

# 2. 设置路由规则images后不需要(/)
router.register(r"skus/images",image.ImageModelViewSet,basename=image)

# -------------- SKU的路由 -------------- #
router.register(r"skus",sku.SKUModelViewSet,basename="sku")

# -------------- 订单管理的路由 -------------- #
router.register(r"orders",order.OrderModelViewSet,basename="orders")

# -------------- 权限管理的路由 -------------- #
router.register(r"permission/perms",permission.PermissionModelViewSet,basename="permission")

# -------------- 分组的路由 -------------- #
router.register(r"permission/groups",group.GroupView,basename="groups")

# -------------- 规格表的路由 -------------- #
router.register(r"goods/specs",spec.SpecView,basename="goods_specs")

# -------------- 品牌管理的路由 -------------- #
router.register(r"goods/brands",brands.BrandView,basename="brands")

# -------------- 商品频道的路由 -------------- #
router.register(r"goods/channels",channel.GoodsChannelView,basename="channels")

# -------------- spu的路由 -------------- #
router.register(r"goods",spu.SPUGoodsView,basename="goods")

# -------------- 规格选项表的路由 -------------- #
router.register(r"specs/options",option.SpecificationOptionView,basename="specs")

# -------------- 管理员的路由 -------------- #
router.register(r"permission/admins",admins.AdminModelViewSet,basename="admins")



# 3. router追加到路由列表当中
urlpatterns += router.urls


